home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / hypercar / xcmd / xrulesde.sit / Xrules™ Demo / card_17476.txt < prev    next >
Encoding:
Text File  |  1991-06-24  |  5.1 KB  |  115 lines

  1. -- card: 17476 from stack: in
  2. -- bmap block id: 17679
  3. -- flags: 4000
  4. -- background id: 7992
  5. -- name: 6-Processing Facts
  6.  
  7.  
  8. -- part 1 (field)
  9. -- low flags: 01
  10. -- high flags: 0007
  11. -- rect: left=2 top=24 right=311 bottom=510
  12. -- title width / last selected line: 0
  13. -- icon id / first selected line: 0 / 0
  14. -- text alignment: 0
  15. -- font id: 22
  16. -- text size: 10
  17. -- style flags: 0
  18. -- line height: 13
  19. -- part name: 
  20.  
  21.  
  22. -- part 3 (button)
  23. -- low flags: 00
  24. -- high flags: 0000
  25. -- rect: left=256 top=314 right=337 bottom=281
  26. -- title width / last selected line: 0
  27. -- icon id / first selected line: 1013 / 1013
  28. -- text alignment: 1
  29. -- font id: 0
  30. -- text size: 12
  31. -- style flags: 0
  32. -- line height: 16
  33. -- part name: Next
  34. ----- HyperTalk script -----
  35. on mouseUp
  36.   go to next card
  37. end mouseUp
  38.  
  39.  
  40.  
  41. -- part contents for card part 1
  42. ----- text -----
  43. When the inference engine needs to discover a fact, it will look for a card having the same name as that fact and, if it finds one, it will display that card and wait to be restarted.  If it does not find a card having the same name as the fact or if the fact is not asserted when the inference engine is restarted, it will look for a handler with the same name as the fact.  When the inference engine summons a card it stops and you must continue the inference process via the "chain" XCMD.   Handlers behave like subroutines.  Do not restart the inference engine when the inference engine invokes a handler.  The inference engine will automatically continue at the conclusion of the handler.
  44.  
  45. NOTE:  Facts that will use handlers must be named with simple strings.  That is, 
  46.        these fact names must not include white space or special characters, and 
  47.        they must not match keywords. 
  48.  
  49. You can change the values of facts when they have been previously asserted.  However, the inference engine will not re-examine or retract rules or their clauses that have already been processed.
  50.  
  51. You can retract a fact by assigning it a null value as follows:
  52.  
  53.      PUTINTOFACT "", fact_id   -- in HyperTalk
  54.  
  55.      PUT "" INTO FACT fact_id  -- in the rule base
  56.  
  57. Note that even though the system considers the fact "not asserted" when it is assigned a null value, the system will still process any daemons using that fact.
  58.  
  59. The response of the system to facts being retracted depends on whether it is forward or backward chaining.  The sections on forward and backward chaining document the responses for each case.
  60.  
  61. You may force a match by using the wildcard (*) operand.  The wildcard operand will match anything except a fact that is not asserted.  You may assign the wildcard operator to a fact via one of the following constructs:
  62.  
  63.      PUTINTOFACT "*", fact_id   -- in HyperTalk
  64.  
  65.      PUT "*" INTO FACT fact_id  -- in the rule base
  66.  
  67. When the fact is compared to anything except a fact that is not asserted, it will evaluate true.  If it is compared to a fact that is not asserted, the system will cease evaluation of the rule if forward chaining or it will attempt to assert the fact if backward chaining, unless the immediate operator(#) is applied to the fact that is not asserted.
  68.  
  69. The following example illustrates the use of the wildcard operand.
  70.  
  71.      put * into fact a
  72.  
  73.      if
  74.        fact a = 123
  75.      then
  76.        put 1 into fact b
  77.  
  78. In the above example, if you backward chain with a goal of "b", the rule will fire, setting fact "b" to 1.  When fact "a" is compared to anything except a fact that is not asserted, it will evaluate true.
  79.  
  80. Similarly, if you compare a fact to a wildcard, it will always evaluate true if it is asserted.  For example, assume the rule base contains the following:
  81.  
  82.      put 123 into fact a
  83.  
  84.      if
  85.        fact a = *
  86.      then
  87.        put 1 into fact b
  88.  
  89. If fact "a" was not asserted, the system would either attempt to assert fact "a" (if backward chaining with a goal of "b") or it would simply cease evaluation of the rule (if forward chaining).  Since fact "a" was asserted, the system considers the clause true regardless of the value of fact "a".
  90.  
  91. The immediate operator will force the inference engine to evaluate a fact at its current value.  The inference engine will not attempt to assert the fact and will not cease processing the rule or daemon.  If the fact is not asserted, the inference engine will use the null string ("") as its value.  The following example illustrates the use of the immediate operator:
  92.  
  93.      fact c
  94.  
  95.      rule "a null"
  96.      if
  97.        fact c = 1 and
  98.        #fact a = ""            -- if fact "a" is not asserted
  99.      then 
  100.        put "" into fact b
  101.  
  102.      rule "a asserted"
  103.      if  
  104.        fact c = 1 and
  105.        #fact a <> ""           -- if fact "a" is asserted
  106.      then 
  107.        put "" into fact b
  108.  
  109. When forward chaining, if fact "c" were set to 1, the rule "a null" would fire.  The system would then examine rule "a asserted" which would prove false because fact "a" is not asserted.
  110.  
  111. When backward chaining (with a goal of "b"), if fact "c" were set to 1, the rule "a null" would fire.  The system would then examine rule "a asserted" which would prove false because fact "a" is not asserted.
  112.  
  113. The immediate operator has no effect when facts are already asserted, as the system would not have attempted to assert them anyway.
  114.  
  115.